// 2025/10/02
// Author: Forever
#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<pair<int, int>> edges[100001];
int n, m, s, dist[100001];

void dijistra(int s)
{
    memset(dist, 0x3f, sizeof dist);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push({ 0, s });
    dist[s] = 0;
    while (!pq.empty()) {
        int v = pq.top().second, d = pq.top().first;
        pq.pop();
        if (dist[v] < d)
            continue;
        for (auto x : edges[v]) {
            int a = x.first, b = x.second;
            if (dist[a] > d + b)
                dist[a] = d + b, pq.push({ dist[a], a });
        }
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> s;
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        edges[u].push_back({ v, w });
    }
    dijistra(s);
    for (int i = 1; i <= n; i++)
        cout << (dist[i] == 0x3f3f3f3f3f3f3f3f ? INT_MAX : dist[i]) << " ";
    return 0;
}